package org.example.com.service.impl;

import org.example.com.pojo.DiscoverConfig;
import org.example.com.mapper.DiscoverConfigMapper;
import org.example.com.service.DiscoverConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DiscoverConfigServiceImpl implements DiscoverConfigService {

    @Autowired
    private DiscoverConfigMapper discoverConfigMapper;

    @Override
    public List<DiscoverConfig> getDiscoverConfigsByType(String configType) {
        return discoverConfigMapper.findByConfigType(configType);
    }

    @Override
    public List<DiscoverConfig> getActiveDiscoverConfigs() {
        return discoverConfigMapper.findActiveConfigs();
    }

    @Override
    public DiscoverConfig getDiscoverConfigById(Integer id) {
        return discoverConfigMapper.findById(id);
    }

    @Override
    @Transactional
    public boolean createDiscoverConfig(DiscoverConfig discoverConfig) {
        return discoverConfigMapper.insert(discoverConfig) > 0;
    }

    @Override
    @Transactional
    public boolean updateDiscoverConfig(DiscoverConfig discoverConfig) {
        return discoverConfigMapper.update(discoverConfig) > 0;
    }

    @Override
    @Transactional
    public boolean deleteDiscoverConfig(Integer id) {
        return discoverConfigMapper.deleteById(id) > 0;
    }
}
